/**
 * Created by will on 2017/9/25.
 */
$(function () {
    $("#add-supply").click(function () {
        window.location.href="./easytrip-supplyadd.html"
    })
    layui.use(['table','laydate','laypage','layer','upload'], function(){
        var table = layui.table
            ,upload = layui.upload
            ,laydate=layui.laydate
            ,laypage=layui.laypage
            ,layer=layui.layer;
     /*   //上传图片
        var uploadInst = upload.render({
            elem: '.easytrip-supplylist .uploadpic'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    /!*$('#demo1').attr('src', result); //图片链接（base64）*!/
                    $('.uploadpic').parent().parent().siblings('.layui-upload-list').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });*/
        //日期控件
        laydate.render({
            elem: '#date1'
            ,theme: '#45a2ff'
        });
        laydate.render({
            elem: '#date2'
            ,theme: '#45a2ff'
        });
        //展示已知数据
        table.render({
            elem: '#supplylist-table'
            ,data: [{
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "未上传"
                ,"state": "启用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }, {
                "supplyname": "湖南易旅科技有限公司"
                ,"settlement": "月结"
                ,"sign": "俞懿洋"
                ,"date": "2017/06/20"
                ,"contract": "下载"
                ,"state": "禁用"
            }]
            ,height:800
            ,cols: [[ //标题栏
                // {checkbox: true, LAY_CHECKED: true} //默认全选
                {field: 'supplyname', title: '供应商名称', width: 278}
                ,{field: 'settlement', title: '结算方式', width: 220}
                ,{field: 'sign', title: '签约人', width: 220}
                ,{field: 'date', title: '签约日期', width: 220}
                ,{field: 'contract', title: '合同', width: 220}
                ,{field: 'state', title: '状态', width: 220}
                ,{title: '操作',width:220, align:'center', toolbar: '#barDemo'}
            ]]
            ,skin: 'line' //表格风格
            /*,page: true //是否显示分页
             ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            ,limits: [5, 7, 10]*/
               ,limit:11 //每页默认显示的数量
               /*,theme:'#45a2ff'*/
        });
        laypage.render({
            elem: 'supplylist-paging'
            ,count: 1000
            ,page:'true'
            ,theme: '#45A2FF'
            ,prev: '<em><</em>'
            ,next: '<em>></em>'
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            ,jump: function(obj){
                console.log(obj)
            }
        });

    });
})